home *** CD-ROM | disk | FTP | other *** search
/ PC User 2002 April / Disc 2 / PCUSER0402D2.iso / software / utils / files / wincron.exe / data1.cab / Sample_Scripts / ftp_master_test.tg < prev    next >
Encoding:
Text File  |  2001-10-20  |  5.4 KB  |  179 lines

  1. ## ftp_master_test.tab
  2. # Perform many FTP functions while handling exceptions.
  3. # Basically, this script does recursive Get, Put, and Delete as well as Rename and Test.
  4. # script assumes:
  5. # 1. There is a temp/foo directory on the remote server 
  6. # 2. There is a temp/foo/test_file.dat file on the remote server 
  7. # 3. There is a c:\temp\foo local directory (tree) filled with all the files and directories
  8. #    you wish to move back and forth.
  9. # 4. the environment variables: USER.SERVER, USER.USERID, and USER.PASSWORD are set elsewhere,
  10. #    perhaps in the global (computer) environment or the local environment of WinCron via 
  11. #    Config.tg or AutoRun.tg. You could also set them here in this this script or hard-code the 
  12. #    values passed to -ftp connect.
  13. {
  14.     -name ftp_master_test
  15.     -start 
  16.     -stop
  17.  
  18.     # tell user what we are about to do
  19.     -action -print ftp master test
  20.  
  21.     # setup local environment
  22.     -action -set LOCAL_DIR=c:\temp\foo
  23.     
  24.     # I set these in my global environment, you can set them here
  25.     #-action -set USER.SERVER=xxx
  26.     #-action -set USER.USERID=yyy
  27.     #-action -set USER.PASSWORD=zzz
  28.  
  29.     # CONNECT TO FTP SERVER
  30.     -action -print connecting to remote ftp server
  31.     -action -onerror connect_fail
  32.     -action -ftp connect handle %USER.SERVER% 21 %USER.USERID% %USER.PASSWORD%
  33.  
  34.     # DEBUG
  35.     #-action -print lastline: %FTP.LASTLINE%
  36.  
  37.     # TEST FOR "test-file" ON REMOTE SERVER
  38.     -action -print testing for "test-file" on remote ftp server
  39.     -action -set OPERATION=test1
  40.     -action -onerror general_failure
  41.     -action -ftp test handle temp/foo/test_file.dat
  42.  
  43.     # DEBUG
  44.     #-action -print lastline: %FTP.LASTLINE%
  45.  
  46.     # GET A FILE FROM REMOTE SERVER
  47.     -action -print getting file from remote ftp server
  48.     -action -set OPERATION=get
  49.     -action -onerror general_failure
  50.     -action -ftp get handle temp/foo/test_file.dat %LOCAL_DIR%\test_file.dat 0
  51.  
  52.     # DEBUG
  53.     #-action -popup Did we get test_file.dat to %LOCAL_DIR%\test_file.dat?
  54.     #-action -print lastline: %FTP.LASTLINE%
  55.  
  56.     # DELETE THE test-file FROM REMOTE SERVER
  57.     -action -print deleting the file from remote ftp server
  58.     -action -set OPERATION=del
  59.     -action -onerror general_failure
  60.     -action -ftp del handle temp/foo/test_file.dat
  61.  
  62.     # DEBUG
  63.     #-action -popup Has temp/foo/test_file.dat been deleted?
  64.     #-action -print lastline: %FTP.LASTLINE%
  65.  
  66.     # PUT A FILE ON REMOTE SERVER
  67.     -action -print putting file back on remote ftp server
  68.     -action -set OPERATION=put
  69.     -action -onerror general_failure
  70.     -action -ftp put handle %LOCAL_DIR%\test_file.dat temp/foo/test_file.dat 0
  71.  
  72.     # DEBUG
  73.     #-action -popup Is temp/foo/test_file.dat back again?
  74.     #-action -print lastline: %FTP.LASTLINE%
  75.  
  76.     # TEST FOR "test-file" ON REMOTE SERVER
  77.     -action -print testing for "test-file" on remote ftp server
  78.     -action -set OPERATION=test2
  79.     -action -onerror general_failure
  80.     -action -ftp test handle temp/foo/test_file.dat
  81.  
  82.     # DEBUG
  83.     #-action -print lastline: %FTP.LASTLINE%
  84.  
  85.     # RENAME "test-file" ON REMOTE SERVER
  86.     -action -print rename the test-file on remote ftp server
  87.     -action -set OPERATION=rename
  88.     -action -onerror general_failure
  89.     -action -ftp rename handle temp/foo/test_file.dat temp/foo/test_file.bak
  90.  
  91.     # DEBUG
  92.     #-action -popup Was temp/foo/test_file.dat renamed to temp/foo/test_file.bak?
  93.     #-action -print lastline: %FTP.LASTLINE%
  94.  
  95.     # TEST FOR test_file.bak ON REMOTE SERVER
  96.     -action -print testing for test-file.bak on remote ftp server
  97.     -action -set OPERATION=test3
  98.     -action -onerror general_failure
  99.     -action -ftp test handle temp/foo/test_file.bak
  100.  
  101.     # DEBUG
  102.     #-action -print lastline: %FTP.LASTLINE%
  103.  
  104.     # RENAME "test-file" ON REMOTE SERVER
  105.     -action -print rename the test-file on remote ftp server
  106.     -action -set OPERATION=rename
  107.     -action -onerror general_failure
  108.     -action -ftp rename handle temp/foo/test_file.bak temp/foo/test_file.dat
  109.  
  110.     # DEBUG
  111.     #-action -print lastline: %FTP.LASTLINE%
  112.  
  113.     # RGET/MGET
  114.     -action -print test recursive get from remote ftp server
  115.     -action -set OPERATION=rget/mget
  116.     -action -onerror general_failure
  117.     -action -ftp rget handle temp/foo/* %LOCAL_DIR% 0
  118.  
  119.     # DEBUG
  120.     #-action -print lastline: %FTP.LASTLINE%
  121.  
  122.     # RDELETE
  123.     -action -print test recursive delete from remote ftp server
  124.     -action -set OPERATION=rdelete
  125.     -action -onerror general_failure
  126.     -action -ftp rdel handle temp/foo/*
  127.  
  128.     # DEBUG
  129.     #-action -popup has temp/foo/* been cleared?
  130.     #-action -print lastline: %FTP.LASTLINE%
  131.  
  132.     # RPUT/MPUT
  133.     -action -print test recursive put to remote ftp server
  134.     -action -set OPERATION=rput/mput
  135.     -action -onerror general_failure
  136.     -action -ftp rput handle %LOCAL_DIR%\* temp/foo 0
  137.  
  138.     # DEBUG
  139.     #-action -popup has temp/foo/* been restored?
  140.     #-action -print lastline: %FTP.LASTLINE%
  141.  
  142.     # TEST FOR "test-file" ON REMOTE SERVER
  143.     -action -print testing for "test-file" on remote ftp server
  144.     -action -set OPERATION=test4
  145.     -action -onerror general_failure
  146.     -action -ftp test handle temp/foo/test_file.dat
  147.  
  148.     # DEBUG
  149.     #-action -print lastline: %FTP.LASTLINE%
  150.  
  151.     # CLOSE FTP CONNECTION
  152.     -action -print closing ftp connection
  153.     -action -ftp close handle 
  154.  
  155.     # DEBUG
  156.     #-action -print lastline: %FTP.LASTLINE%
  157.  
  158.     -action -print done!
  159. }
  160.  
  161. # connection failed
  162. {
  163.     -name connect_fail
  164.     -action -print FTP open connection failed with error:
  165.     -action -print %FTP.ERROR%
  166.     -action -return abort
  167. }
  168.  
  169. # general failed
  170. {
  171.     -name general_failure
  172.     -action -print FTP %OPERATION% failed with error:
  173.     -action -print %TG.LAST_ERROR%
  174.     -action -print Closing connection.
  175.     -action -ftp close handle
  176.     -action -return abort
  177. }
  178.  
  179.